package com.qdu.service.impl;

import com.qdu.bean.Power;
import com.qdu.bean.User;
import com.qdu.mapper.UserMapper;
import com.qdu.service.UserService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User getUser(String name) {
        return userMapper.getUser(name);
    }

    @Override
    public List<Power> selectPosition() {
        return userMapper.selectPosition();
    }

    @Override
    public boolean register(User user) {
        try {
            user.setPassword(DigestUtils.md5Hex(user.getPassword()));
            userMapper.register(user);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public User getUser(String name, String password) {
        return userMapper.getUserB(name,password);
    }
}
